import request from '@/utils/request';
import { AxiosPromise } from 'axios';

/**
 * 查询联系人合作伙伴列表
 * @param query
 * @returns {*}
 */
export const listLead = (query?: LeadVO): AxiosPromise<LeadVO[]> => {
  return request({
    url: '/hrp/lead/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询联系人合作伙伴详细
 * @param id
 */
export const getLead = (id: number | undefined ): AxiosPromise<LeadVO> => {
  return request({
    url: '/hrp/lead/' + id,
    method: 'get'
  });
};

/**
 * 新增联系人合作伙伴
 * @param data
 */
export const addLead = (data: LeadVO) => {
  return request({
    url: '/hrp/lead',
    method: 'post',
    data: data
  });
};

/**
 * 修改联系人合作伙伴
 * @param data
 */
export const updateLead = (data: LeadVO) => {
  return request({
    url: '/hrp/lead',
    method: 'put',
    data: data
  });
};

/**
 * 删除联系人合作伙伴
 * @param id
 */
export const delLead = (id: number | string | Array<number | undefined>) => {
  return request({
    url: '/hrp/lead/' + id,
    method: 'delete'
  });
};

/**
 * 执行
 * @param data
 */
export const turnLead = (data: LeadVO) => {
  return request({
    url: '/hrp/lead/turnLead',
    method: 'put',
    data: data
  });
};

export const listLeadQuote = (query?: LeadQuoteVO): AxiosPromise<LeadQuoteVO[]> => {
  return request({
    url: '/hrp/lead/quoteList',
    method: 'get',
    params: query
  });
};

/**
 * 查询订单列表
 * @param id
 */
export const getQuoteListById = (id: number): AxiosPromise<LeadQuoteVO[]> => {
  return request({
    url: '/hrp/lead/getQuoteList/' + id,
    method: 'get'
  });
};

export const delLeadQuote = (quoteId: string | string[]) => {
  return request({
    url: '/hrp/lead/quoteId/' + quoteId,
    method: 'delete'
  });
};

export const getCommentById = (commentId: number): AxiosPromise<LeadCommentVO[]> => {
  return request({
    url: '/hrp/lead/getCommentList/' + commentId,
    method: 'get'
  });
};

export interface LeadVO extends BaseEntity, PageQuery {
  /** id */
  id?: number;

  /** 线索名 */
  name?: string;

  /** 客户id */
  partnerId?: number;

  /** 客户名 */
  partnerName?: string;

  /** 归属销售 */
  salesId?: string|number;

  /** 归属销售名 */
  salesName?: string;

  /** 客户来源 */
  source?: string;

  /** 客户阶段 */
  stage?: string;

  /** 失去原因 */
  lostReason?: string;

  /** 下次跟单时间 */
  nextTime?: string;

  /** 备注 */
  remark?: string | null;

  /** 备注 */
  createBy?: number;

  /** 备注 */
  updateBy?: number;

  /** 订单List */
  quoteList?: LeadQuoteVO[];

  /** 备注List */
  commentList?: LeadCommentVO[];
}
export interface LeadQuoteVO extends PageQuery {
  id?: number;
  name?: string;
  quoteId?: string;
  productId?: number;
  productName?: string;
  batchCode?: string;
  measureUnit?: string;
  price?: number;
  purchasePrice?: number;
  quantity?: number;
  whId?: number;
  areaId?: number;
  totalMoney?: number;
  discountMoney?: number;
  costMoney?: number;
  expireDate?: any;
  isStock?: boolean;
}
export interface LeadCommentVO {
  id?: number;
  stage?: string | number;
  remark?: string | null | number;
  createDept?: number;
  createTime?: string | number;
  createBy?: number;
  nickName?: string;
}
